/**
 * ResponseUtils.java
 * 作者：刘仕亮
 * Jun 20, 2018 创建文件
 */
package org.example.common.util;

import org.example.common.enumerate.ResponseCode;
import org.example.common.model.vo.base.ResponseVO;

import java.util.List;
import java.util.Map;

/**
 **************************************************
 * 响应工具类
 * 
 * @version 1.0.0
 * @author  lsliang
 **************************************************
 */
public final class ResponseUtils {

	private ResponseUtils() {
		super();
	}
	
	/**
	 * 成功并含有内容
	 * @param
	 * @return
	 * @since 1.0.0
	 * @author lsliang Jun 20, 2018 创建方法
	 */
	public static <T> ResponseVO<T> success(T data) {
		ResponseVO<T> result = new ResponseVO<T>();
        result.setCode(ResponseCode.SUCCESS.getCode());
        result.setMsg(ResponseCode.SUCCESS.getMsg());
        result.setData(data);
        return result;
    }

	/**
	 * 成功无返回内容
	 * @return
	 * @since 1.0.0
	 * @author lsliang Jun 20, 2018 创建方法
	 */
    public static <T> ResponseVO<T> success() {
        return success(null);
    }

    /**
     * 错误调用
     * @param responseCode ResponseCode
     * @return
     * @since 1.0.0
     * @author lsliang Jun 20, 2018 创建方法
     */
    public static <T> ResponseVO<T> error(ResponseCode responseCode) {
    	ResponseVO<T> result = new ResponseVO<T>();
        result.setCode(responseCode.getCode());
        result.setMsg(responseCode.getMsg());
        return result;
    }
    
    public static <T> ResponseVO<T> error(String code, String msg) {
    	ResponseVO<T> result = new ResponseVO<T>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

	public static <T> ResponseVO<T> error(Map<String, List<String>> errorMap) {
		ResponseVO<T> result = new ResponseVO<T>();
		result.setCode(ResponseCode.PARAMETER_EXCEPTION.getCode());
		result.setParameterError(errorMap);
		return result;
	}
}
